import React from "react";
import {Dimensions, StyleSheet, View} from "react-native";
import NetworkErrorView from "./NetworkErrorView";
import LoadingView from "./LoadingView";


const WIN_WIDTH = Dimensions.get("window").width;

//
class ContainerView extends React.Component {

  constructor() {
    super();
    this.state = {};
  }

  //隐藏navigationBar
  static navigationOptions = ({navigation, navigationOptions}) => {
    return {
      title: "ContainerView"
    };
  };

  componentDidMount() {
    const {navigation} = this.props;
  }

  render() {
    let children = this.props.children;
    if (this.props.error) {
      children = <NetworkErrorView onPress={() => this.props.reload && this.props.reload()}/>;
    } else if (!this.props.data) {
      children = <LoadingView/>;
    }

    return (<View
      style={{flex: 1, alignItems: "stretch", width: WIN_WIDTH}}
    >
      {children}
    </View>)
      ;
  }
}

const styles = StyleSheet.create({});
export default ContainerView;
